package com.bdcom.comp;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JPanel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bdcom.util.PlannerUtil;
/**
 * 长宽标签
 * @author Administrator
 *
 */
@Component
public class WHLabelPanel extends JPanel{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String m=PlannerUtil.getString("m");
	@Autowired
	private CanvasPanel canvasPanel;
	
	public WHLabelPanel() {
		super();
		// TODO Auto-generated constructor stub
		setPreferredSize(new Dimension(0,50));
	}
	
	@Override
	public void paint(Graphics g) {
		// TODO Auto-generated method stub
		super.paint(g);
		
		int panelWidth = this.getWidth();
		
		int panelHeight = this.getHeight();
		
		double height=0,width=0,scale=1.0;
		
		if(canvasPanel.getCanvasModel()!=null)
		{
			width=canvasPanel.getCanvasModel().getMapWidth();

			height=canvasPanel.getCanvasModel().getMapHeight();
			
			scale=canvasPanel.getCanvasModel().getRoomPercent();
		}
		String txtwh=PlannerUtil.getString("width")+":"+width+" "+m+"    "+PlannerUtil.getString("height")+":"+height+" "+m;
		
		String txtscale=PlannerUtil.getString("view scale")+":"+scale;

		FontMetrics metrics =g.getFontMetrics();
		
		int size=metrics.stringWidth(txtwh);

		Graphics2D g2d=(Graphics2D) g;
		
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		
		g2d.setColor(Color.black);

		if(size<panelWidth)
		{

			int x=(panelWidth-size)/2;
			
			int y=panelHeight/2;
			
			g2d.drawString(txtwh, x, y);
			
		}
		
		size=metrics.stringWidth(txtscale);
		
		if(size<panelWidth)
		{

			int x=(panelWidth-size)/2;
			
			int y=panelHeight/2+metrics.getHeight();
			
			g2d.drawString(txtscale, x, y);
			
		}
	}

}
